package com.zl.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.system.comm.util.CheckUtil;
import com.system.comm.util.JsonUtils;
import com.system.common.pojo.BisCustomUser;
import com.system.common.pojo.BisNurseProject;
import com.system.common.pojo.BisShop;
import com.zl.service.ZlBisNurseProjectService;
import com.zl.service.ZlBisShopService;



@Controller
@RequestMapping("project")
public class wechatProjectController {
	
	@Autowired
	private ZlBisNurseProjectService bisNurseProjectService;
	@Autowired
	private ZlBisShopService zlBisShopService;
	@Autowired
	private ZlBisNurseProjectService zlBisNurseProjectService;
	
	@RequestMapping("windex")
	public String index(Model model,HttpServletRequest request){
		HttpSession session=request.getSession();
		BisCustomUser bis=zlBisShopService.queryUserBeautyNum("20000003");
		session.setAttribute("user", bis);
		List<BisNurseProject> projectList=bisNurseProjectService.selectByExample(null);
		
		model.addAttribute("projectList", projectList);
		return "/wechat/project/findProject";
	}
	@RequestMapping("goSubscribeProject")
	public String goSubscribeProject(Model model,String projectId,String shopId){
		BisShop shopPO=zlBisShopService.selectByPrimaryKey(shopId);
		BisNurseProject project=bisNurseProjectService.selectByPrimaryKey(projectId);
		model.addAttribute("shopPO", shopPO);
		model.addAttribute("project", project);
		return "/wechat/project/subscribeProject";
	}
	
	@RequestMapping("initMyProject")
	public  String initMyProject(Model model, HttpServletRequest request, HttpServletResponse response, HttpSession session) throws IOException {
		String bagId=request.getParameter("bag_id");
		model.addAttribute("bagId",bagId);
		return "wechat/project/myProject";
	}
	
	@RequestMapping(value = "showProjectDetail")
	public  String showProjectDetail(Model model,String projectId,HttpServletRequest request, HttpServletResponse response,HttpSession session) throws IOException {
		BisNurseProject project=zlBisNurseProjectService.selectByPrimaryKey(projectId);
		model.addAttribute("project", project);
		return "wechat/project/showProjectDetail";
	}
	
	@RequestMapping("listMyProject")
	public  void listMyProject(HttpServletRequest request, HttpServletResponse response,HttpSession session) throws IOException {
		BisCustomUser bisCustomUser=CheckUtil.getUserSession(session);
		List<BisNurseProject> bisNurseProjects=bisNurseProjectService.selectByBagId(bisCustomUser,request);
		
		String str=JsonUtils.toJson(bisNurseProjects);
		CheckUtil.responseW(response, str);
		
	}
	

}
